package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: yankaiyue
 * @Create: 2025/8/6 8:55
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;

    //16）统计各店铺-评价次数的柱状图（5分）
    @RequestMapping("/getListCount")
    public JSONObject getListCount(){
        List<Map> list = orderInfoService.getListCount();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray categories = new JSONArray();
        for (Map map : list) {
            categories.add(map.get("name"));
        }
        data.put("categories",categories);
        JSONArray series = new JSONArray();
        JSONObject series1 = new JSONObject();
        series1.put("name","评价次数");
        JSONArray data1 = new JSONArray();
        for (Map map : list) {
            data1.add(map.get("rating_num"));
        }
        series1.put("data",data1);

        data.put("series",series);
        series.add(series1);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getListPeople")
    public List<Map> getListPeople(){
        List<Map> listPeople = orderInfoService.getListPeople();
        return listPeople;
    }
    @RequestMapping("/getListGoodRating")
    public List<Map> getListGoodRating(){
        List<Map> listGoodRating = orderInfoService.getListGoodRating();
        return listGoodRating;
    }
    //17）统计各店铺-平均评分的折线图（5分）
    @RequestMapping("/getListAvgRating")
    public JSONObject getListAvgRating(){
        List<Map> list = orderInfoService.getListAvgRating();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        jsonObject.put("data",data);
        JSONArray categories = new JSONArray();
        for (Map map : list) {
            categories.add(map.get("name"));
        }
        data.put("categories",categories);
        JSONArray series = new JSONArray();
        JSONObject series1 = new JSONObject();
        series1.put("name","平均评分");
        JSONArray data1 = new JSONArray();
        for (Map map : list) {
            data1.add(map.get("avg_rating"));
        }
        series1.put("data",data1);

        data.put("series",series);
        series.add(series1);
        return jsonObject;
    }
}
